package com.yishusmt.mobsmt.serviceimpl;

import com.yishusmt.mobsmt.dto.base.Result;
import com.yishusmt.mobsmt.entity.UpdateVersionEntity;
import com.yishusmt.mobsmt.mapper.UpdateVersionEntityMapper;
import com.yishusmt.mobsmt.mapper.UpdateVersionInfoMapper;
import com.yishusmt.mobsmt.service.VersionControlService;
import com.yishusmt.mobsmt.utils.TipsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.yishusmt.mobsmt.enums.VersionEnum.HAVE_TO;
import static com.yishusmt.mobsmt.enums.VersionEnum.NO_NEED;
import static com.yishusmt.mobsmt.enums.VersionEnum.NO_TO;

/**
 *  版本控制
 *
 * @author zhangyi
 * @date 2018/8/16 17:29
 */
@Service
public class VersionControlServiceImpl implements VersionControlService {

    @Autowired
    private UpdateVersionInfoMapper updateVersionInfoMapper;

    /**
     * 版本更新
     *
     * @param version
     * @return
     */
    @Override
    public Result versionControl(String version) {
        List<UpdateVersionEntity> updateVersionEntities = updateVersionInfoMapper.selectHighVersion();
        UpdateVersionEntity[] versionEntities = new UpdateVersionEntity[]{null};
        updateVersionEntities.stream().forEach(temp -> versionEntities[0] = temp);
        if(version != versionEntities[0].getVersion()){
            if(versionEntities[0].getStatus() == 1){
                return TipsUtil.returnTips(HAVE_TO,versionEntities[0]);
            }else{
                return TipsUtil.returnTips(NO_NEED,versionEntities[0]);
            }
        }else{
            return TipsUtil.returnTips(NO_TO,"正常");
        }
    }
}
